package com.tanhua.exception;

import com.baomidou.mybatisplus.extension.api.R;
import com.tanhua.model.domain.ErrorResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice//异常处理类注解
public class ExecptionAdvice {


    @ExceptionHandler(BusinessExecption.class)
    public ResponseEntity execptionHandler(BusinessExecption b){
        b.printStackTrace();
        ErrorResult errorResult = b.getErrorResult();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
    }

    //全局异常
    @ExceptionHandler(Exception.class)
    public ResponseEntity execptionAll(Exception e){
        e.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ErrorResult.error());
    }
}
